// const currency = require('currency.js');
import currency from "currency.js";
// 封装函数
export function performOperation(operation, a, b, precision = 2) {
  let result;
  a = String(a);
  b = String(b);
  switch (operation) {
    case "add":
      result = currency(a).add(b).value;
      break;
    case "subtract":
      result = currency(a).subtract(b).value;
      break;
    case "multiply":
      result = currency(a).multiply(b).value;
      break;
    case "divide":
      if (b !== '0') {
        result = currency(a).divide(b).value;
      } else {
        result = 0;
      }
      break;
    default:
      result = 0;
  }
  return currency(result, { precision: precision });
}
